package com.google.code.solrdimension.spring;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.InputStream;

/**
 * This is the configuration containing all User-configurable attributes
 * 
 * @author mhc
 * 
 */
public class ApplicationConfig {

    private String solrDimensionXmlConfigFilePath;

    public String getSolrDimensionXmlConfigFilePath() {
        return solrDimensionXmlConfigFilePath;
    }

    public void setSolrDimensionXmlConfigFilePath(String solrDimensionXmlConfigFilePath) {
        this.solrDimensionXmlConfigFilePath = solrDimensionXmlConfigFilePath;
    }

    public InputStream getSolrDimensionXmlConfigFileAsInputStream() {

        InputStream stream = null;

        if (solrDimensionXmlConfigFilePath != null && !solrDimensionXmlConfigFilePath.isEmpty()) {

            // first try a class path
            stream = this.getClass().getResourceAsStream(solrDimensionXmlConfigFilePath);
            
            if (stream == null){
                
                //now try file path
                try {
                    stream = new FileInputStream(solrDimensionXmlConfigFilePath);
                } catch (FileNotFoundException e) {
                    e.printStackTrace();
                }
                
            }

        }
        return stream;
    }

}
